<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>sticky</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        body, html{
            height: 1210px;
            width: 100px;
        }

        main {
            width: 100vw;
            height: 100vh;
            /*background-color: cyan;*/
            position: relative;
        }
        section{
            height: 200px;
        }
        /* 没触发之前，static定位， 触发后 fixed布局*/
        h2{
            position: sticky;
            top: 0;
        }
        h2:nth-of-type(1){
            background-color: purple;
        }
        h2:nth-of-type(2){
            background-color: gray;
        }
    </style>
</head>
<body>
<main>
    <section></section>
    <h2>ck</h2>
    <section></section>
    <h2>kb</h2>
</main>
</body>
</html>
